package cn.wonderland.netflix.controller;

import cn.wonderland.netflix.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/{id}")
    @HystrixCommand(fallbackMethod = "getUserFallback")
    public User getUser(@PathVariable("id")Long id) {
//        String url = "http://localhost:1010/user/" + id;
        String url = "http://user-server/user/" + id;
        return restTemplate.getForObject(url, User.class);
    }


    public User getUserFallback(Long id){
        return new User(-1L,"进入order熔断","稍后再试！");
    }
}
